package com.adv.ems.model.dto;

import cn.hutool.core.comparator.CompareUtil;
import lombok.Data;
import java.util.Date;
import java.util.List;

@Data
public class TimeEnergyUseInfoDTO implements Comparable<TimeEnergyUseInfoDTO> {
    private Long itemId;
    private Long energyId;
    private Date date;
    private Double increaseRealValue;
    private Double increaseStandValue;
    private Double increaseCashValue;

    public static TimeEnergyUseInfoDTO sumAll(Long energyId, List<QueryPointEnergyResultDTO> list) {
        double increaseStandValue = 0;
        double increaseCashValue = 0;
        double increaseRealValue = 0;
        for (QueryPointEnergyResultDTO item : list) {
            increaseStandValue = item.getIncreaseStandValue() + increaseStandValue;
            increaseCashValue = item.getIncreaseCashValue() + increaseCashValue;
            if (energyId != null) {
                increaseRealValue = item.getIncreaseRealValue() + increaseRealValue;
            }
        }
        TimeEnergyUseInfoDTO result = new TimeEnergyUseInfoDTO();
        result.setIncreaseStandValue(increaseStandValue);
        result.setIncreaseCashValue(increaseCashValue);
        result.setIncreaseRealValue(increaseRealValue);
        return result;
    }

    @Override
    public int compareTo(TimeEnergyUseInfoDTO o) {
        if (o.getIncreaseStandValue().equals(this.getIncreaseStandValue())) {
            return CompareUtil.compare(this.getItemId(), o.getItemId());
        }
        return CompareUtil.compare(this.getIncreaseStandValue(), o.getIncreaseStandValue());
    }
}
